// =============================================================
// CKeyValue
// ---------------------------------------
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr or woorung@nhncorp.com
// Date : Sep. 4, 2007
// =============================================================
#include "CKeyValue.h"

CKeyValue::CKeyValue() 
{ 
	key = ""; 
	value = "";
}

CKeyValue::CKeyValue(const CKeyValue &obj) 
{
	key = obj.key;
	value = obj.value;
}

CKeyValue::~CKeyValue() 
{
	key = "";
	value = "";
}

bool CKeyValue::blindlyEquals(const CObject *rhs) const 
{
	const CKeyValue *casted_rhs = dynamic_cast<const CKeyValue *>(rhs);
	// perform comparisons on private message

	bool isEqual = false;
	if(this->key==casted_rhs->key) isEqual = true;
	return (isEqual&&CObject::blindlyEquals(rhs));
}

const type_info *CKeyValue::getTypeEquiv() const 
{
	return &typeid(this);
}


CKeyValue *CKeyValue::clone() const 
{
	return new CKeyValue(*this);
}

CKeyValue &CKeyValue::operator=(CKeyValue &obj) 
{
	// identity test
	if(this==&obj) return *this;

	key = obj.key;
	value = obj.value;

	return *this;
}

int CKeyValue::set(char *k, char *v) 
{
	key = k;
	value = v;

	return key.length();
}

char *CKeyValue::getKey() 
{ 
	return (char *) key.c_str(); 
}

char *CKeyValue::getValue() 
{ 
	return (char *) value.c_str(); 
}

void CKeyValue::setKey(char *k)
{
	key = k;
}

void CKeyValue::setValue(char *v)
{
	value = v;
}

void CKeyValue::print() 
{ 
	cout << key << "=" << value << endl; 
}
